<style lang="less" scoped>
.cf {
  clear: both;
}
.noDate_page {
  padding-top:2rem;
}
</style>

<!--司机端提货签收列表页-->
<template>
	<div class="gridContainer">
    <manage-header></manage-header>
    <header-car :status="3"></header-car>


    <scroller lock-x scrollbar-y use-pullup :height="scrollerHeight" v-if="totalRecords > 0" :pullup-config="ScrollerConfig" ref="Scroller">
      <div>
        <div class="acpt-list" v-for="(item, index) in datas">

          <div class="car-pc-title cf listing">
            <span class="f-l"><i class="llse llse-huoche"></i> <b class="atvno">{{item.ATVNo}}</b></span>
            <!-- <em class="f-r"><div class="btn ml10" @click="transferAll(item.ATVGuid)">整车中转</div></em> -->
          </div>
          
          <div class="acpt-list">
            <div class="acpt-list-wrap" v-for="(bbitem, index) in item.list" :class="index+1 === item.list.length?'mb30':'lineb-dash'">
              <div class="acpt-list-head cf">
                <span class="txt f-l">业务单号：{{bbitem.BBillNo}}</span>
              </div>
              <div class="displayflex acpt-list-body lineb">
                <span class="cargo">
                  <i class="iconfont icon-cargo"></i>
                  <p>{{bbitem.Pkgs}}件</p>
                </span>
                <div class="txt flex1">
                  <p class="ft17">{{bbitem.PickContacts}} {{bbitem.PickContactsTel}}</p>
                  <p>取货地址：{{bbitem.DepartureCity | city}}{{bbitem.DepartureDistrict | district}}{{bbitem.DepartureAddress}}</p>
                  <p>送货地址：{{bbitem.ArrivalCity | city}}{{bbitem.ArrivalDistrict | district}}{{bbitem.ArrivalAddress}}</p>
                </div>
              </div>
              <div class="btn-grp txt-rit">
                <!-- <div class="btn ml10" @click="viewOrderDetail(bbitem.BBillGuid)">详情</div> -->
                <div class="btn ml10" @click="goDelivery(bbitem.BBillNo, bbitem.Guid)">交货</div>
                <!-- <div class="btn ml10" @click="transfer(bbitem.Guid, bbitem.RowNo)">物流中转</div> -->
              </div>
            </div>
          </div>
        </div>
      </div>
    </scroller>

    <div class="noDate_page" v-if="totalRecords == 0">
			<div class="noDate_icon"><i class="iconfont icon-null"></i></div>
			暂无数据，请通知所属公司派单！
		</div>
    <div class="w100fix"></div>
    <footer-menu :status='1'></footer-menu>
  </div>
</template>

<script>
import manageHeader from "@/components/core/header/manage.header.vue";
import headerCar from '@/components/core/header/driver-progress.vue'
import footerMenu from "@/components/core/footer/manage.footer.vue";
import { mapGetters, mapState } from "vuex";

export default {
  components: {
    footerMenu, 
    headerCar,
    manageHeader,
  },
  data() {
    return {
      datas:[
        {
          ATVNo:'',
          AtvGuid:'',
          list:[],
        }
      ],

      totalRecords:0,
      noMore:false,
      ScrollerConfig: {
        content: "",
        downContent: "",
        height: 0,
        loadingContent: "",
        upContent: ""
      }
    }
  },
  computed:{
    ...mapState({
      pagetitle: state => state.cfg.appBarTitle,
      showstate: state => state.cfg.showAppBar,
    }),
    ...mapGetters({
      scrollerHeight: "cfg/getConHeight"
    }),
    userinfo(){
      return localStorage.userinfo?JSON.parse(localStorage.userinfo):null;
    }
  },
  created(){
    this.getData();
  },
  mounted(){
    this.$store.dispatch("cfg/setConHeight");
  },
  methods: {
    getData(){
      let query = {
        DriverGuid: this.userinfo.StaffID,
        State: "52",
        Grouped:'Y'
      };
      this.Ajax.post("GetDriverOrderList", query).then(resp => {
        if (resp.IsSuccess) {
          this.totalRecords = resp.TotalRecords;
          if (resp.Datas && resp.Datas.length > 0) {
            let map = {},
                args = [];
            resp.Datas.forEach((x) => {
              if(!map[x.ATVNo]){
                args.push({
                  ATVNo: x.ATVNo,
                  ATVGuid: x.AtvGuid,
                  list: [x]
                });
                map[x.ATVNo] = x;
              } else {
                for(var i = 0; i < args.length; i++){
                  if(args[i].ATVNo == x.ATVNo){
                    args[i].list.push(x);
                    break;
                  }
                }
              }
            })
            args = args.sort(by("ATVNo"));
            this.datas = args;
          }
        } else {
          this.Toast({
            message: "列表为空，请稍后刷新"
          });
        }
      });

      let by = function(name){
        return function(o, p){
          var a, b;
          if (typeof o === "object" && typeof p === "object" && o && p) {
            a = o[name];
            b = p[name];
            if (a === b) {
              return 0;
            }
            if (typeof a === typeof b) {
              return a < b ? -1 : 1;
            }
            return typeof a < typeof b ? -1 : 1;
          }
          else {
            throw ("error");
          }
        }
      };
    },
    
    transferAll(guid){
      this.$router.push({
        path:'/driver/transferAll',
        query:{
          Guid: guid
        }
      });
    },

    transfer(guid, rowNo){
      this.$router.push({
        path:'/driver/transfer',
        query:{
          Guid: guid,
          RowNo: rowNo
        }
      });
    },

    viewOrderDetail(BBillGuid) {
      this.$router.push({
        path:'/driver/senddingdetailorder',
        query:{
          Guid: BBillGuid,
        }
      });
    },

    goDelivery(BBillNo, AtvGuid){
      this.$router.push({
        path:'carDeliveryCheck',
        query:{
          BBillNo: BBillNo,
          AtvGuid: AtvGuid,
        }
      });
    }
  }
}
</script>